{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "pip install numpy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 2, 3, 4, 5])"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 1.1创建一个一维数组\n",
    "d1 = np.array([1,2,3,4,5])\n",
    "d1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 属性：size数据大小\n",
    "d1.size"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 属性：type数据类型\n",
    "d1.type"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "numpy.ndarray"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(d1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 属性：ndim数据维度\n",
    "d1.ndim"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14])"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 1.2创建二维数组\n",
    "d2 = np.arange(15)\n",
    "d2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0,  1,  2,  3,  4],\n",
       "       [ 5,  6,  7,  8,  9],\n",
       "       [10, 11, 12, 13, 14]])"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 增加行、列维度\n",
    "d2 = d2.reshape(3,5)\n",
    "d2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "15"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 打印一下相关属性\n",
    "d2.size"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d2.ndim"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "numpy.ndarray"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(d1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\u001B[0;31mDocstring:\u001B[0m\n",
       "array(object, dtype=None, *, copy=True, order='K', subok=False, ndmin=0,\n",
       "      like=None)\n",
       "\n",
       "Create an array.\n",
       "\n",
       "Parameters\n",
       "----------\n",
       "object : array_like\n",
       "    An array, any object exposing the array interface, an object whose\n",
       "    ``__array__`` method returns an array, or any (nested) sequence.\n",
       "    If object is a scalar, a 0-dimensional array containing object is\n",
       "    returned.\n",
       "dtype : data-type, optional\n",
       "    The desired data-type for the array. If not given, NumPy will try to use\n",
       "    a default ``dtype`` that can represent the values (by applying promotion\n",
       "    rules when necessary.)\n",
       "copy : bool, optional\n",
       "    If ``True`` (default), then the array data is copied. If ``None``,\n",
       "    a copy will only be made if ``__array__`` returns a copy, if obj is\n",
       "    a nested sequence, or if a copy is needed to satisfy any of the other\n",
       "    requirements (``dtype``, ``order``, etc.). Note that any copy of\n",
       "    the data is shallow, i.e., for arrays with object dtype, the new\n",
       "    array will point to the same objects. See Examples for `ndarray.copy`.\n",
       "    For ``False`` it raises a ``ValueError`` if a copy cannot be avoided.\n",
       "    Default: ``True``.\n",
       "order : {'K', 'A', 'C', 'F'}, optional\n",
       "    Specify the memory layout of the array. If object is not an array, the\n",
       "    newly created array will be in C order (row major) unless 'F' is\n",
       "    specified, in which case it will be in Fortran order (column major).\n",
       "    If object is an array the following holds.\n",
       "\n",
       "    ===== ========= ===================================================\n",
       "    order  no copy                     copy=True\n",
       "    ===== ========= ===================================================\n",
       "    'K'   unchanged F & C order preserved, otherwise most similar order\n",
       "    'A'   unchanged F order if input is F and not C, otherwise C order\n",
       "    'C'   C order   C order\n",
       "    'F'   F order   F order\n",
       "    ===== ========= ===================================================\n",
       "\n",
       "    When ``copy=None`` and a copy is made for other reasons, the result is\n",
       "    the same as if ``copy=True``, with some exceptions for 'A', see the\n",
       "    Notes section. The default order is 'K'.\n",
       "subok : bool, optional\n",
       "    If True, then sub-classes will be passed-through, otherwise\n",
       "    the returned array will be forced to be a base-class array (default).\n",
       "ndmin : int, optional\n",
       "    Specifies the minimum number of dimensions that the resulting\n",
       "    array should have.  Ones will be prepended to the shape as\n",
       "    needed to meet this requirement.\n",
       "like : array_like, optional\n",
       "    Reference object to allow the creation of arrays which are not\n",
       "    NumPy arrays. If an array-like passed in as ``like`` supports\n",
       "    the ``__array_function__`` protocol, the result will be defined\n",
       "    by it. In this case, it ensures the creation of an array object\n",
       "    compatible with that passed in via this argument.\n",
       "\n",
       "    .. versionadded:: 1.20.0\n",
       "\n",
       "Returns\n",
       "-------\n",
       "out : ndarray\n",
       "    An array object satisfying the specified requirements.\n",
       "\n",
       "See Also\n",
       "--------\n",
       "empty_like : Return an empty array with shape and type of input.\n",
       "ones_like : Return an array of ones with shape and type of input.\n",
       "zeros_like : Return an array of zeros with shape and type of input.\n",
       "full_like : Return a new array with shape of input filled with value.\n",
       "empty : Return a new uninitialized array.\n",
       "ones : Return a new array setting values to one.\n",
       "zeros : Return a new array setting values to zero.\n",
       "full : Return a new array of given shape filled with value.\n",
       "copy: Return an array copy of the given object.\n",
       "\n",
       "\n",
       "Notes\n",
       "-----\n",
       "When order is 'A' and ``object`` is an array in neither 'C' nor 'F' order,\n",
       "and a copy is forced by a change in dtype, then the order of the result is\n",
       "not necessarily 'C' as expected. This is likely a bug.\n",
       "\n",
       "Examples\n",
       "--------\n",
       ">>> import numpy as np\n",
       ">>> np.array([1, 2, 3])\n",
       "array([1, 2, 3])\n",
       "\n",
       "Upcasting:\n",
       "\n",
       ">>> np.array([1, 2, 3.0])\n",
       "array([ 1.,  2.,  3.])\n",
       "\n",
       "More than one dimension:\n",
       "\n",
       ">>> np.array([[1, 2], [3, 4]])\n",
       "array([[1, 2],\n",
       "       [3, 4]])\n",
       "\n",
       "Minimum dimensions 2:\n",
       "\n",
       ">>> np.array([1, 2, 3], ndmin=2)\n",
       "array([[1, 2, 3]])\n",
       "\n",
       "Type provided:\n",
       "\n",
       ">>> np.array([1, 2, 3], dtype=complex)\n",
       "array([ 1.+0.j,  2.+0.j,  3.+0.j])\n",
       "\n",
       "Data-type consisting of more than one element:\n",
       "\n",
       ">>> x = np.array([(1,2),(3,4)],dtype=[('a','<i4'),('b','<i4')])\n",
       ">>> x['a']\n",
       "array([1, 3], dtype=int32)\n",
       "\n",
       "Creating an array from sub-classes:\n",
       "\n",
       ">>> np.array(np.asmatrix('1 2; 3 4'))\n",
       "array([[1, 2],\n",
       "       [3, 4]])\n",
       "\n",
       ">>> np.array(np.asmatrix('1 2; 3 4'), subok=True)\n",
       "matrix([[1, 2],\n",
       "        [3, 4]])\n",
       "\u001B[0;31mType:\u001B[0m      builtin_function_or_method"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# numpy官网地址：numpy.org / numpy.org.cn\n",
    "np.array?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}